1117B - Emotes - CodeForces Solution


greedy math sortings *1000

Please click on ads to support us..

Python Code:

n, m, k = [int(x) for x in input().split()]
emotes = sorted([int(x) for x in input().split()], reverse=True)

if k + 1 <= m:
    m, r = divmod(m, k + 1)
    print(m * (k * emotes[0] + emotes[1]) + r * emotes[0])
else:
    print(k * emotes[0])

C++ Code:

//Athour : 7amok4a
//Return Dark ^_^ &_&
#include <bits/stdc++.h>
using namespace  std;
#ifndef ONLINE_JUDGE
#include "debug.h"
#else
#define debug(...)
#endif
#define YU ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(0);
//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//
void A7med_YU(){
  long long n , m , k ;  cin >> n >> m >> k ;
  vector < long  long > v ( n ) ;
  for ( auto &i : v ) cin >> i;
  sort ( v.begin() , v.end() ) ;
  if ( v[n-1] == v[n-2] ) return void ( cout << m * v[n-1] );
  long long out = ( m / ( k+1 ) ) * ( k * v[n-1] + v[n-2]) + ( ( m % ( k+1) ) * v[n-1] ) ;
  cout << out << '\n'; 


}
int32_t main(void) {
    YU;
    #ifndef ONLINE_JUDGE
    Matter();
    #endif
    int t = 1;  //cin >> t;
    while (t--) {
      A7med_YU();
    }
    #ifndef ONLINE_JUDGE
      end_clock();
    #endif
}


Comments

Submit
0 Comments
More Questions

754B - Ilya and tic-tac-toe game
760A - Petr and a calendar
1573A - Countdown
166A - Rank List
1631B - Fun with Even Subarrays
727A - Transformation from A to B
822B - Crossword solving
1623A - Robot Cleaner
884B - Japanese Crosswords Strike Back
862B - Mahmoud and Ehab and the bipartiteness
429A - Xor-tree
1675C - Detective Task
950A - Left-handers Right-handers and Ambidexters
672B - Different is Good
1C - Ancient Berland Circus
721A - One-dimensional Japanese Crossword
1715B - Beautiful Array
60B - Serial Time
453A - Little Pony and Expected Maximum
1715A - Crossmarket
1715C - Monoblock
1512C - A-B Palindrome
1679B - Stone Age Problem
402A - Nuts
792A - New Bus Route
221A - Little Elephant and Function
492C - Vanya and Exams
1369B - AccurateLee
892B - Wrath
999A - Mishka and Contest